#ifndef __sensor_ir_ir_sensor_h__
#define __sensor_ir_ir_sensor_h__

#include <ros/ros.h>

#include <string>

#define IR_SENSOR_ADC_STEPS 1000

typedef enum {
	IRSensorTypeShort,
	IRSensorTypeLong
} IRSensorType;

class IRSensor {
public:
	IRSensor(int id, float x, float y, float z, float angle, IRSensorType type);

	float simulatedMeasure(ros::ServiceClient *distance_client);
	float measure();

	float getX() { return x_; }
	float getY() { return y_; }
	float getZ() { return z_; }
	float getAngle() { return angle_; }
	float getMinRange() { return min_range_; }
	float getMaxRange() { return max_range_; }

	void setADCValue(int value);
private:
	int id_;
	float x_;
	float y_;
	float z_;
	float angle_;
	float min_range_;
	float max_range_;
	IRSensorType type_;

	// Average readings
	int num_average_readings_;
	int *average_readings_;
	int current_average_position_;

	// Lookup table for the ADC value readings to actual distances.
	float distance_lookup_[IR_SENSOR_ADC_STEPS];

	void readCalibrationFromFile(std::string filename);
};

#endif
